package com.atguigu.tingshu.album.api;

import com.atguigu.tingshu.album.config.MinioConstantProperties;
import com.atguigu.tingshu.album.service.FileUploadService;
import com.atguigu.tingshu.common.result.Result;
import io.minio.MinioClient;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@Tag(name = "上传管理接口")
@RestController
@RequestMapping("api/album")
public class FileUploadApiController {

    private final MinioConstantProperties minioConstantProperties;
    private final FileUploadService fileUploadService;

    @Autowired
    public FileUploadApiController(MinioConstantProperties minioConstantProperties, FileUploadService fileUploadService) {
        this.minioConstantProperties = minioConstantProperties;
        this.fileUploadService = fileUploadService;
    }
    /**
     * @description: 上传文件
     * @author Petrichor 
     * @date 2023/12/21 12:52
     * @param file 文件上传流
     * @return minio 的url
    **/
    @PostMapping("/fileUpload")
    public Result fileUpload(MultipartFile file){
        String url = fileUploadService.fileUpload(file,minioConstantProperties);
        return Result.ok(url);
    }

}
